/* Copyright © 2010 LPRM
Universidade Federal do Espírito Santo - RNP-GT CWTools

This file is part of JoinUs!.

JoinUs! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

JoinUs! is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JoinUs!. If not, see <http://www.gnu.org/licenses/>. */
package android.isisufes.home2;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

class MyListAdapter extends BaseAdapter {
	LayoutInflater inflate; // ViewInflate inflate;
	private View[] mDialogue;
	private View[] mTitles;
	private boolean[] mExpanded;
	private Context mContext;
	int size;

	public MyListAdapter(Context context, LayoutInflater i, View[] v, View[] t,	int first, int size) {
		mContext = context;
		this.size = size;
		inflate = i;
		mDialogue = v;
		mTitles = t;
		mExpanded = new boolean[mTitles.length];
		if (first >= 0 && first < mTitles.length) {
			mExpanded[first] = true;
		}
	}

	public int getCount() {
		return this.mTitles.length;
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		CampView sv;
		if (convertView == null) {
			sv = new CampView(mContext, mTitles[position], mDialogue[position], mExpanded[position], position, size);
		} else {
			sv = (CampView) convertView;
			sv.setTitle(mTitles[position]);
			sv.setDialogue(mDialogue[position]);
			sv.setExpanded(mExpanded[position]);
		}
		return sv;
	}

	public void toggle(int position) {
		if (position < mDialogue.length) {
			for (int i = 0; i < mDialogue.length; i++) {
				mExpanded[i] = false;
			}
			mExpanded[position] = true;
			notifyDataSetChanged();
		}
	}
}
